<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   zhaozilong
 * @Last Modified time: 2018-11-24 08:45:44
 */

namespace app\home\controller;
use app\BaseController;
use app\admin\logic\AdminUser as AdminUserLogic;
use think\Loader;
use think\facade\Config as thinkConfig;

class HomeBase extends BaseController {

	function initialize() {
		parent::initialize();
		
		//系统开关
// 		if (!config('system.toggle_web_site')) {
// 			$this->error('站点已经关闭，请稍后访问~');
// 		}
		
		//保存和获取配置
		$this->saveAndGetConfigForHome();
		
		$adminuid = AdminUserLogic::isLogin();
		$this->assign('adminuid', $adminuid);

		if ($adminuid) {
			$adminUserDao = model('SystemUser', 'admin');
			$adminInfo = $adminUserDao->getInfo($adminuid);
			$this->assign('adminInfo', $adminInfo);
		}
	}
	
	function saveAndGetConfigForHome() {
		$sys_identify = 'mall_config';
		$configInfo = cache($sys_identify);
		if (empty($configInfo)) {
			$configDao = model('SystemConfig', 'admin');
			$configInfo = $configDao->getConfigsBySpace('mall');
			cache($sys_identify, $configInfo, 3600);
		}
		//echo '<br>商城缓存配置configInfo:';print_r($configInfo);
		$this->mallConfigInfo = $configInfo;
		$this->assign('mallConfigInfo', $configInfo);
		$cache_config = [];
		$cache_config = $configInfo;
		thinkConfig::set($cache_config, 'mall'); //添加系统配置
	}
	
	function _initialize000() {
		parent::initialize();
		
		include UC_CLIENT_ROOT."config.inc.php";

		$winduid = 0;

		$list = explode("\t", addslashes(_authcode(cookie('user_login_auth'))));
		if (count($list) > 1) {
			list($winduid, $windpwd) = $list;
		}

		if ($winduid) {
			$userModel = model('common/User');
			$winddb = $userModel->getInfo($winduid);
			//print_r($winddb);

			$this->winduid = $winduid;
			$this->windname = $winddb['username'];
			$this->winddb = $winddb;

			$this->assign('winduid', $winduid);
			$this->assign('windname', $winddb['username']);
			$this->assign('winddb', $winddb);

			$this->onlineip = get_client_ip();
			if (in_array($this->winddb['groupid'], array(3, 4, 46))) { //管理员编辑的情况
				$this->isManage = 1;
				$this->assign('isManage', $this->isManage);
			}
		} else {
			$this->assign('winduid', 0);
			$this->assign('windid', '');
		}
		//$this->currentUser = cookie('user_login_auth');
		//print_r($this->currentUser);

		//$this->assign('current_user', $this->currentUser);
		
		//主题的公共资源目录
		$theme_public_path = THEME_PATH.'home/';
		$this->assign('header_menus',logic('Nav')->getNavigationMenus('header'));
		$this->assign('_theme_public_', $theme_public_path); // 页面公共继承模版
		$this->assign('_theme_public_layout', $theme_public_path.'layout.html'); // 页面公共继承模版
	}

	function setSeoFrontHome($first_name = '') {
		$site_seo_title = config('system.seo_title');
		$site_seo_keywords = config('system.site_keywords');
		$site_seo_description = config('system.seo_description');
		if ($first_name) {
			$site_seo_title .= $first_name.'_'.$site_seo_title;
		}

		$this->assign('site_seo_title', $site_seo_title);
		$this->assign('site_seo_keywords', $site_seo_keywords);
		$this->assign('site_seo_description', $site_seo_description);

		$this->assign('sideName', $first_name);
	}

}